import {PageContainer,} from '@ant-design/pro-components';
import React, {useEffect} from 'react';
import { Button, Card, Form, Input, InputNumber, message } from "antd";
import { edit, save } from "./service";
import {FormInstance} from "antd/lib";

export default () => {
  const [form] = Form.useForm<FormInstance>()

  useEffect(() => {
    edit({}).then(result=>{
      form.setFieldsValue(result.data);
    })
  },[])

  return (
    <PageContainer title={false}>
      <Card>
        <Form form={form} labelCol={{span: 6}} wrapperCol={{span: 12}} onFinish={(formValues)=>{
          console.log(formValues);
          save(formValues).then((result)=>{
            message.success(result.data).then();
            window.location.reload();
          })
        }}>
          <Form.Item name='id' style={{display:'none'}}>
            <Input />
          </Form.Item>
          <Form.Item label='预测第几个数' name='walletIndex' rules={[{required:true}]} extra="5:表示预测第1个数，4：预测第2个数，3：预测第3个数，2：预测第4个数，1：预测第5个数">
            <InputNumber step={1} min={0} precision={0} style={{width:'100%'}} />
          </Form.Item>
          <Form.Item label='预测使用的历史数据量' name='predictionCount' rules={[{required:true}]}>
            <InputNumber step={1} min={0} precision={0} style={{width:'100%'}} />
          </Form.Item>
          <Form.Item wrapperCol={{offset: 6}}>
            <Button type="primary" htmlType="submit">保存</Button>
          </Form.Item>
        </Form>
      </Card>
    </PageContainer>
  );
};
